package presentacion;

import integracion.DatabaseManager;
import integracion.UsuarioDAO;


import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class for Servlet: Sesion
 *
 */
 public class EliminarEmpleadoEje extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
 {
   static final long serialVersionUID = 1L;


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		doAll(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		doAll(request, response);
	}

	private void doAll(HttpServletRequest request, HttpServletResponse response) throws IOException
	{

		if(request.getParameter("accion").equals("EliminarUsuario"))
		{
			int cedula = Integer.parseInt(request.getParameter("opciones"));

			try
			{
				UsuarioDAO dao = new UsuarioDAO(DatabaseManager.getConnection());
				dao.eliminarUsuarioId(cedula);

				if(dao.eliminarUsuarioId(cedula)==true)
				{
					response.sendRedirect("index.jsp?page=GestionarEmpleadoEje/GestionarEmpleadoEjes");
					return;
				}
				else
				{
					response.sendRedirect("index.jsp?error=No se pudo eliminar");
					return;
				}
			}
			catch (SQLException e)
			{
				e.printStackTrace();
			}

		}


	}
}